package webmote.server;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TilesServlet extends HttpServlet {

	private static final long serialVersionUID = 4484652131763888054L;

	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        int tileId = Integer.valueOf(request.getParameter("id"));
        try {
            response.getOutputStream().write(SessionImages.getSessionImages(request.getSession()).getTileImage(tileId));
        } catch (IOException exception) {
            System.err.println("Cannot create png tile: " + tileId);
            exception.printStackTrace();
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
    }

}
